package com.hyq.prototype.examples;

import java.util.Random;

/**
 * 客户端
 * @author Janus
 */
public class Client {
	//最大发送用户
	private static int maxMailCount=10;
	
	public static void main(String[] args) {
		//定义邮件，活动名称、活动内容
		Mail mail = new Mail(new advTemplate());
		for (int i = 0; i <= maxMailCount; i++) {
			Mail cloneMail = mail.clone();
			int randNum=(int) (Math.random()*10);
			cloneMail.setReceiver(getRandString(randNum)+"@126.com");
			cloneMail.setCall(getRandString(randNum)+getCall(randNum));
			//自动发送邮件
			sendMail(cloneMail);
		}
		
	}
	//发送邮件
	public static void sendMail(Mail mail){
		System.out.println("邮件主题："+mail.getName() +"\t收件人："+mail.getCall()+"\t\t收件人邮箱:"+mail.getReceiver() +"\t\t邮件发送成功！");
	}
	//获取先生还是女士
	public static String getCall(int sex){
		int sexNum=sex%2;
		String sexName="";
		switch(sexNum){
			case 0 :
				sexName="先生";
				break;
			case 1 :
				sexName="女士";
				break;
		}
		return sexName;
	}
	//获得指定长度的随机字符串
	public static String getRandString(int maxLength){
		String source ="abcdefghijklmnopqrskuvwxyz";
		StringBuffer sb = new StringBuffer();
		Random rand = new Random();
		for(int i=0;i<maxLength;i++){
			sb.append(source.charAt(rand.nextInt(source.length())));
		}
		return sb.toString();
	}
}
